{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="form form-horizontal" id="form" method="post" action="{:\\think\\Request::instance()->baseUrl()}">
        <input type="hidden" name="id" value="{$vo.id ?? ''}">
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>批次号：</label>
            <div class="formControls col-xs-6 col-sm-3">
                <select  class="input-text" id="batch" placeholder="批次号" name="batch" value="{$batch ?? ''}" datatype="*" nullmsg="请选择批次号">
                    <option value="">请选择</option>
                    {volist name="arr_batch" id="vo"}
                    <option class="text-c" value="{$vo.batch}">
                        {$vo.batch}
                    </option>
                    {/volist}
                </select>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>优惠码段：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="number" class="input-text start_num" placeholder="起始号码" name="start_num" value="" readonly/> --
                <input type="number" class="input-text end_num" placeholder="结束号码" name="end_num" value="" readonly/>
                剩余<span class="number_plus" style="color: red;"> * </span>张
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">分配卡数：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="number" class="input-text num" placeholder="数量" name="num" value="" datatype="*" nullmsg="请输入分配卡数"> 张
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">备注：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <textarea class="textarea" placeholder="" name="remark" onKeyUp="textarealength(this,100)">{$vo.remark ?? ''}</textarea>
                <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius" >&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script>
    $(function () {

        $("[name='company_type'][value='{$vo.company_type ?? ''}']").prop("checked", true);
        $("[name='offline_type'][value='{$vo.offline_type ?? ''}']").prop("checked", true);

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form").Validform({
            tiptype: 2,
            ajaxPost: true,
            showAllError: true,
            callback: function (ret){
                ajax_progress(ret);
            }
        });


        //优惠码号段失焦时 判断是否为空 显示提示信息
//        $('.start_num').blur(function(){
//            var start_num = $(this).val();
//            if(start_num == ''){
//                $('.num').removeClass('col-xs-3 col-sm-3').addClass('Validform_checktip Validform_wrong').empty().html('请输入优惠码号段');
//            }else{
//                $('.num').removeClass('Validform_checktip Validform_wrong').addClass('col-xs-3 col-sm-3').empty();
//            }
//        });
//        $('.end_num').blur(function(){
//            var end_num = $(this).val();
//            if(end_num == ''){
//                $('.num').removeClass('col-xs-3 col-sm-3').addClass('Validform_checktip Validform_wrong').empty().html('请输入优惠码号段');
//            }else{
//                $('.num').removeClass('Validform_checktip Validform_wrong').addClass('col-xs-3 col-sm-3').empty();
//            }
//        });

        //选择批次号后 将该批次号传入后台
        $('#batch').change(function(){
            var batch = $(this).val();
            $.ajax({
                url:'/admin/Sales/number',
                type:'post',
                dataType:'json',
                data:{batch:batch},
                success:function(number_min){
                    $('.start_num').val(number_min.number_min);
                    $('.end_num').val(number_min.number_max);
                    $('.number_plus').html(' '+number_min.number_plus+' ');
                }
            })
        });

    })
</script>
{/block}
